import 'package:flutter/material.dart';
import 'package:we_chat/constants.dart' show Constants;
import 'package:we_chat/constants.dart' show AppColors;

class NavigationIconView {
  final String _title;
  final IconData _icon;
  final IconData _activeIcon;
  final BottomNavigationBarItem item;

  NavigationIconView(
      {Key key, String title, IconData icon, IconData activeIcon})
      : _title = title,
        _icon = icon,
        _activeIcon = activeIcon,
        item = new BottomNavigationBarItem(
            icon: Icon(
              icon,
              color: Color(AppColors.TabIconNormal),
            ),
            activeIcon: Icon(
              activeIcon,
              color: Color(AppColors.TabIconActive),
            ),
            title: new Text(
              title,
              style: TextStyle(
                  fontSize: 14.0, color: Color(AppColors.TabIconNormal)),
            ),
            backgroundColor: Colors.white);
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  List<NavigationIconView> _navigationViews;

  @override
  void initState() {
    super.initState();
    _navigationViews = [
      NavigationIconView(
          title: "微信",
          icon: IconData(
            0xe600,
            fontFamily: Constants.IconFontFamily,
          ),
          activeIcon: IconData(
            0xe61b,
            fontFamily: Constants.IconFontFamily,
          )),
      NavigationIconView(
          title: "通讯录",
          icon: IconData(0xe655, fontFamily: Constants.IconFontFamily),
          activeIcon: IconData(0xe604, fontFamily: Constants.IconFontFamily)),
      NavigationIconView(
          title: "发现",
          icon: IconData(0xe609, fontFamily: Constants.IconFontFamily),
          activeIcon: IconData(0xe603, fontFamily: Constants.IconFontFamily)),
      NavigationIconView(
          title: "我",
          icon: IconData(0xe64a, fontFamily: Constants.IconFontFamily),
          activeIcon: IconData(0xe62d, fontFamily: Constants.IconFontFamily))
    ];
  }

  @override
  Widget build(BuildContext context) {
    final BottomNavigationBar bottomNavigationBar = BottomNavigationBar(
      items: _navigationViews.map((NavigationIconView view) {
        return view.item;
      }).toList(),
      currentIndex: 0,
      type: BottomNavigationBarType.fixed,
      onTap: (int index) {
        print("点击的是第$index个tap");
      },
    );

    return Scaffold(
      appBar: AppBar(
        title: Text("微信"),
        actions: [
          IconButton(
              icon: Icon(IconData(0xe613, fontFamily: Constants.IconFontFamily),
                  size: 22.0),
              onPressed: () {
                print('点击了搜索按钮');
              }),
          IconButton(
            icon: Icon(IconData(0xe62a, fontFamily: Constants.IconFontFamily),
                size: 22.0),
            onPressed: () {
              print('显示下拉列表');
            },
          ),
          Container(
            width: 10.0,
          )
        ],
      ),
      body: Container(
        color: Colors.red,
      ),
      bottomNavigationBar: bottomNavigationBar,
    );
  }
}
